package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.SysRoleMapper;
import com.atguigu.spzx.manager.service.SysRoleService;
import com.atguigu.spzx.model.entity.system.SysRole;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author syh
 * @create 2023-08-15 17:17
 */
@Service
public class SysRoleServiceImpl implements SysRoleService {
    @Resource
    SysRoleMapper sysRoleMapper;
    @Override
    public PageInfo<SysRole> findPageByKeyword(Integer pageNum, Integer pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize,true,true,null);
        List<SysRole> sysRoles = sysRoleMapper.selectPageByKeyword(keyword);

        return new PageInfo<>(sysRoles);
    }

    @Override
    public void deletById(Long id) {
        sysRoleMapper.deleteById(id);
    }

    @Override
    public void save(SysRole sysRole) {
        sysRole.setCreateTime(new Date());
        sysRole.setUpdateTime(new Date());
        sysRoleMapper.save(sysRole);
    }

    @Override
    public SysRole getById(Long id) {
        return sysRoleMapper.getById(id);
    }

    @Override
    public void updateById(SysRole sysRole) {
        //前端更新提交的参数为
        sysRole.setUpdateTime(new Date());
        sysRoleMapper.updateById(sysRole);
    }

    @Override
    public List<SysRole> listAll(Long userId) {
        return sysRoleMapper.selectAllRolesByUserId(userId);
    }
}
